package com.hp.mvc;

import org.springframework.core.convert.converter.Converter;

/**
 * 自定义转换器
 */
public class StudentConvertor implements Converter<String,Student> {

    @Override
    public Student convert(String s) {
        //id-name-age-subject
        String[] strings = s.split("\\-");
        Student student = new Student();
        student.setId(Integer.parseInt(strings[0]));
        student.setName(strings[1]);
        student.setAge(Integer.parseInt(strings[2]));
        student.setSubject(strings[3]);
        return student;
    }
}
